package com.xiatl.cgi.server.cgi.exception;

import com.xiatl.cgi.server.cgi.utils.ResultUtil;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;


/**
 * @program: ExceptionConfig
 * @description: 异常配置
 * @author: xiatl
 * @create: 2020-08-07 16:04
 **/
@Order(999999)
@RestControllerAdvice
public class ExceptionConfig extends ResultUtil {

    /**
     * 处理AppException异常
     */
    @ExceptionHandler(value = CgiException.class)
    @ResponseStatus(HttpStatus.OK)
    public Object appExceptionHandle(HttpServletRequest req, CgiException e) {
        return super.resError(e.getMessage(), e.getErrorCode());
    }

    /**
     * 系统异常捕获处理
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseStatus(HttpStatus.OK)
    public Object exceptionHandler(Exception e) {
        e.printStackTrace();
        return super.resError("服务器繁忙，请稍后重试");
    }

    /**
     * 系统异常捕获处理
     */
    @ExceptionHandler(value = RuntimeException.class)
    @ResponseStatus(HttpStatus.OK)
    public Object runtimeExceptionHandle(Exception e) {
        e.printStackTrace();
        return super.resError("服务器繁忙，请稍后重试");
    }

}
